//
//  FQOrganizationViewController.swift
//  SwiftProject
//
//  Created by 董駸 on 2022/8/19.
//

import UIKit

class FQOrganizationViewController: BaseViewController, UITableViewDataSource, UITableViewDelegate {
    let mainTable = UITableView(frame: .zero, style: .plain)
    
    override func viewDidLoad() {
        super.viewDidLoad()
        navigationBarType = .light
        // Do any additional setup after loading the view.
    }
    
    override func initSubviews() {
        super.initSubviews()
        
        let headerImage = UIImageView(imageString: "icon_recommend")
        headerImage.frame = CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: 158~)
        
        mainTable.delegate = self
        mainTable.dataSource = self
        mainTable.rowHeight = 126~
        mainTable.separatorStyle = .none
        mainTable.backgroundColor = .qmui_color(withHexString: "f4f6fa")
        mainTable.register(FQOrganizationTableViewCell.self, forCellReuseIdentifier: "cell")
        mainTable.tableHeaderView = headerImage
        view.addSubview(mainTable)
        
        mainTable.snp.makeConstraints { make in
            make.left.right.bottom.equalToSuperview()
            make.top.equalTo(NavigationContentTop)
        }
        
        requestData()
    }
    
    override func requestData() {
        NetworkManager.manager.request(targetType: .productInfo, responseModelType: NetworkDefualtModel.self) { responseModel in
            if responseModel.code != .successCode {
                QMUITips.showError(responseModel.msg)
                return
            }
            
        }
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        10
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! FQOrganizationTableViewCell
        cell.model = FQOrganizationModel()
        return cell
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
        let vc = FQProductDetailViewController()
        navigationController?.qmui_pushViewController(vc, animated: true)
    }
    
    override func setupNavigationItems() {
        super.setupNavigationItems()
        title = "合作机构"
    }
}
